import { Heap } from "../10_堆结构Heap/04_堆结构封装_二叉堆";

class PriorityQueue<T> {
  private heap: Heap<T> = new Heap();

  enqueue(value: any) {
    this.heap.insert(value);
  }

  dequeue(): T | undefined {
    return this.heap.extract();
  }

  peek(): T | undefined {
    return this.heap.peek();
  }

  isEmpty() {
    return this.heap.isEmpty();
  }

  size() {
    return this.heap.size();
  }

  print() {
    this.heap.print();
  }
}

class Student {
  name: string;
  score: number;
  constructor(name: string, score: number) {
    this.name = name;
    this.score = score;
  }
  valueOf() {
    return this.score;
  }
}

const pQueue = new PriorityQueue<Student>();
pQueue.enqueue(new Student("why", 21));
pQueue.enqueue(new Student("juice", 19));
pQueue.enqueue(new Student("red", 78));
pQueue.enqueue(new Student("green", 95));

pQueue.print();
while (!pQueue.isEmpty()) {
  console.log(pQueue.dequeue());
}

export {};
